#!/bin/sh
# - mount_max
# - thread_model
# - write_ratelimit
# - writeback_cache

if [ -n "$mount_max" ]; then
	mount_max=${mount_max%%[a-zA-Z_]*}
else
	mount_max=10000
fi
stack_mount_points=$(echo $mount_points | cut -f-$mount_max -d' ')
keep_mount_points=$(echo $mount_points | cut -f$((mount_max+1))- -d' ')

[ -n "$write_ratelimit" ] && export FUSE_WB=${write_ratelimit%M*}

[ "$thread_model" = serialized ] && options="$options -s "
[ "$writeback_cache" = wc ] && options="$options -o writeback_cache "

for mnt in $stack_mount_points
do
	fuse_mnt=/fs/fuse/$(basename $mnt)
	mkdir -p $fuse_mnt
    mkdir -p /c/fuse/example
    cd /c/fuse/example
    wget http://web.mit.edu/~ecprice/fuse-2.7.0/example/fusexmp_fh.c
    gcc -Wall `pkg-config fuse --cflags --libs` fusexmp_fh.c -c -o fusexmp_fh.o
    gcc -Wall `pkg-config fuse --cflags --libs` fusexmp_fh.o -o fusexmp_fh  -lulockmgr -lfuse
	log_cmd /c/fuse/example/fusexmp_fh $options -o modules=subdir,subdir=$mnt $fuse_mnt || exit
	fuse_mount_points="${fuse_mount_points}$fuse_mnt "
done

cat >> $TMP/env.yaml <<EOF

# setup/fuse
mount_points: $fuse_mount_points $keep_mount_points
EOF
